#include <iostream>
#include <functional>
#include <iterator>
#include <string>
#include <unordered_map>
#include <vector>
#include <time.h>

using namespace std;

int testIntKeys()
{
    unordered_map<int, string> dict;
    unordered_map<int, string> dictTwo;
    vector<pair<int, string> > v;
    clock_t start = clock();
    for(int i = 0; i < 1000000; i++)
    {
        dict.emplace(make_pair(i, to_string(i)));
    }
    cout << "unordered_map emplace time " << clock() - start << endl;
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        dictTwo.insert(make_pair(i, to_string(i)));
    } 
    cout << "unordered_map insert time " << clock() - start << endl; 
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        v.push_back(make_pair(i, to_string(i)));
    }   
    cout << "vector insert time " << clock() - start << endl; 
    bool dummy = false;
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {
        dummy = dummy ^ (dict.find(i) != dict.end()); 
    }
    cout << "unordered_map search time " << clock() - start << endl;
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        dummy = dummy ^ v[i].first; 
    }   
    cout << "vector index addressing time " << clock() - start << endl;    
    return dummy;
}

int testStringKeys()
{
    unordered_map<string, int> dict;
    unordered_map<string, int> dictTwo;
    vector<pair<string, int> > v;
    clock_t start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        dict.emplace(make_pair(to_string(i), i));
    }   
    cout << "unordered_map emplace time " << clock() - start << endl;
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        dictTwo.insert(make_pair(to_string(i),i));
    }   
    cout << "unordered_map insert time " << clock() - start << endl; 
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        v.push_back(make_pair(to_string(i), i));
    }   
    cout << "vector insert time " << clock() - start << endl; 
    bool dummy = false;
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        dummy = dummy ^ (dict.find(to_string(i)) != dict.end()); 
    }   
    cout << "unordered_map search time " << clock() - start << endl;
    start = clock();
    for(int i = 0; i < 1000000; i++)
    {   
        dummy = dummy ^ v[i].second; 
    }   
    cout << "vector index addressing time " << clock() - start << endl;    
    return dummy;
}

int main()
{
    int ret = 0;
    ret += testIntKeys();
    ret += testStringKeys();
    return ret;
}
